#ifndef __HDVB_DBCOMMON_H
#define __HDVB_DBCOMMON_H
/*
    libhdvbd - Library for building sophisticated DVB applications
    Copyright (C) 2012 Tony Houghton <h@realh.co.uk>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser general Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser general Public License for more details.

    You should have received a copy of the GNU Lesser general Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/* Some routines useful for all types of database we use */

#include <glib.h>

#include <sqlite3.h>

G_BEGIN_DECLS

typedef void (*HdvbDbCreator)(sqlite3 *sql, gpointer handle);

/* Opens a database. If it doesn't already exist it calls creator and adds the
 * version table if version >= 0. Otherwise it verifies the version if version
 * >= 0
 */
sqlite3 *
hdvb_db_open(const char *filename, int version,
        HdvbDbCreator creator, gpointer handle);

/* Reports an sqlite3 error */
void
hdvb_db_complain(sqlite3 *sql, int code, const char *format, ...);

/* Prepares a statement with error handling */
sqlite3_stmt *
hdvb_db_prepare_statement(sqlite3 *sql, const char *statement);

/* exec with error handling */
gboolean
hdvb_db_exec(sqlite3 *sql, const char *statement);

/* Prints error message if result != SQLITE_ROW || SQLITE_OK */
int
hdvb_db_step(sqlite3_stmt *stmt);

G_END_DECLS

#endif /* __HDVB_DBCOMMON_H */
